/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package course.providers.jpa;

import course.ya.doc.from.code.model.ast.StatementTree;
import java.io.Serializable;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author def
 */
@Stateless
public class TreeProvider implements Serializable {
    
    private static final long serialVersionUID = -7857250231354852186L;
    
    @PersistenceContext(unitName = "webPartPU")
    protected EntityManager em;

    public TreeProvider() {
    }
    
    public StatementTree create() {
        StatementTree entity = new StatementTree();
        em.persist(entity);
        return entity;
    }

    public void update(StatementTree entity) {
        em.merge(entity);
    }

    public void delete(StatementTree entity) {
        em.remove(em.merge(entity));
    }

    public StatementTree findById(long id) {
        return (StatementTree) em.find(StatementTree.class, id);
    }

    public List<StatementTree> findAll() {
        Query q = em.createNamedQuery("StatementTree.findAll");
        return (List<StatementTree>) q.getResultList();
    }
    
}
